package com.lyf.juc.practice.nju;

import java.util.concurrent.TimeUnit;

/**
 * 异步的示例
 * @author LYF
 * @date 2022/7/7
 */

class Person implements Runnable{
    private String name;
    private String type;//工作类型

    public Person(String name, String type) {
        this.name = name;
        this.type = type;
    }

    @Override
    public void run() {
        String threadName = Thread.currentThread().getName();
        while (true){
            if("老师".equals(type)){
                System.out.println(name+"上课中...");


            }else if("学生".equals(type)){
                System.out.println(name+"听课...");
            }
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    void buyDrink(){
        System.out.println(name+":::买水...");
    }
}

public class AsyncDemo {

    public static void main(String[] args) {
        Person teacher = new Person("李云飞","老师");
        Person student = new Person("丁子文","学生");

        Thread t1 = new Thread(teacher,"thread-1");
        Thread t2 = new Thread(student,"thread-2");


        // 同步--
        t1.start();
        t2.start();


    }
}
